package fun.coding.effective.java;

import java.util.Date;

public class Period {
    
    private final Date start;
    private final Date end;
    
    /**
     * 
     * @param start
     * @param end
     * @throws PeriodTimeException if start is after end.
     */
    public Period(final Date start, final Date end) throws PeriodTimeException {
        if(start.after(end)) {
            throw new PeriodTimeException(start + " is after " + end);
        }
        
        //end = new Date(); can't do this since it is final
        //end.setDate(2); but i can still change the content of the object since the reference is not changed.  
        this.start = start;
        this.end = end;
    }
    
    public class PeriodTimeException extends Exception {
        
        public PeriodTimeException(String msg) {
            super(msg);
        }
    }
    
}
